package com.example.cores_middle_activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.example.cores_middle_activity.Utils.ViewUtil;

public class EditActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_edit);


        EditText numberInput = findViewById(R.id.et_num);
        EditText passwordInput = findViewById(R.id.et_pwd);

        // 验证账号11位
        passwordInput.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean isFocus) {
                if (!isFocus) return;

                String numberString = numberInput.getText().toString();
                if (numberString.isEmpty()) return;

                if (numberString.length() < 11) {
                    numberInput.requestFocus();
                    Toast.makeText(EditActivity.this, "请输入11位手机号", Toast.LENGTH_LONG).show();
                }
            }
        });

        // 密码6位数时隐藏输入法
        passwordInput.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (editable.length() == 6) {
                    ViewUtil.hideOneInputMethod(EditActivity.this, passwordInput);
                }
            }
        });
    }
}